package cn.lhx.blog.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.lhx.blog.dao.DaoComment;
import cn.lhx.blog.pojo.Article;
import cn.lhx.blog.pojo.Comment;
import cn.lhx.blog.service.CommentService;
@Transactional
public class CommentServiceBean implements CommentService {
	@Resource(name="daoComment")
	private DaoComment daoComment;
	/* (non-Javadoc)
	 * @see cn.lhx.blog.service.bean.CommentService#saveComment(cn.lhx.blog.pojo.Comment)
	 */
	public Comment saveComment(Comment comment){
		daoComment.insert(comment);
		return comment;
	}
	/* (non-Javadoc)
	 * @see cn.lhx.blog.service.bean.CommentService#delComment(cn.lhx.blog.pojo.Comment)
	 */
	public int delComment(int id){
		 
		 return daoComment.delete(id);
	}
	/**
	 * 按时间顺序获得评论列表
	 */
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<Comment> getComments(int begin, int size) {
		int _begin=begin;
		int _size=size;
		List<Comment> comments = new ArrayList<Comment>();
		comments=(List<Comment>) daoComment.getList(_begin, _size);
		return comments;
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public long statsCommentCount(){
		long count=(Long)daoComment.executeQuery("select count(a.id) from Comment a").get(0);
		return count;
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Comment getComment(int id) {
		return (Comment)daoComment.getById(id);
	}
	public Comment setStatus(int id, String status) {
		Comment comt=(Comment)daoComment.getById(id);
		comt.setStatus(status);
		return comt;
	}
	

}
